﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="select_user.aspx.cs" Inherits="AnyOffice.general.system.workflow.flow_type.select_user" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title></title>		
		<script src="/aspnet_client/core/function.js"></script>
		<script Language="JavaScript">
var userlist=new Array();
<%=strUserList%>

var parent_window;
if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	parent_window = window.parent.opener;
else
	parent_window = parent.dialogArguments;

function  uncheck_all()
{
   for (check_i=0; check_i<document.all.tags("input").length; check_i++)
  {
  	document.all.tags("input")[check_i].checked=false;
  }
}

function set_op(user_id,user_name)
{
  uncheck_all();
  document.getElementById("opbox_"+user_id).checked=true;
}

function unset_op()
{   
   uncheck_all();
}

function click_user(user_id)
{
  TO_VAL=parent_window.document.getElementById("AutoUser").value;
  TO_NAME=parent_window.document.getElementById("AutoUserName").value;
  OP_VAL=parent_window.document.getElementById("AutoUserOp").value;

  targetelement=document.getElementById(user_id);
  user_name=targetelement.getAttribute("name");

  if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
  {   
    if(TO_VAL.indexOf(user_id+",")==0)    
       parent_window.document.getElementById("AutoUser").value=parent_window.document.getElementById("AutoUser").value.replace(user_id+",","");
   
    if(TO_VAL.indexOf(","+user_id+",")>0)   
       parent_window.document.getElementById("AutoUser").value=parent_window.document.getElementById("AutoUser").value.replace(","+user_id+",",",");
     
    if(TO_NAME.indexOf(user_name+",")==0)
       parent_window.document.getElementById("AutoUserName").value=parent_window.document.getElementById("AutoUserName").value.replace(user_name+",","");
     
    if(TO_NAME.indexOf(","+user_name+",")>0)
       parent_window.document.getElementById("AutoUserName").value=parent_window.document.getElementById("AutoUserName").value.replace(","+user_name+",",",");
      
    if(OP_VAL==user_id)
    {
       parent_window.document.getElementById("AutoUserOp").value="";
       parent_window.document.getElementById("AutoUserOpName").value="";
       unset_op();    
    }
  }
  else
  {
    parent_window.document.getElementById("AutoUser").value+=user_id+",";
    parent_window.document.getElementById("AutoUserName").value+=user_name+",";
    
    if(OP_VAL=="")
    {
        parent_window.document.getElementById("AutoUserOp").value=user_id;
        parent_window.document.getElementById("AutoUserOpName").value=user_name;
        set_op(user_id,user_name);
    }
  }
  begin_set();
}

function click_op(op_id)
{
  TO_VAL=parent_window.document.getElementById("AutoUser").value;
  OP_VAL=parent_window.document.getElementById("AutoUserOp").value;
  
  targetelement=document.getElementById(op_id);
  
  user_id=op_id.substr(0,op_id.length-3);
  user_name=targetelement.getAttribute("name");

  if(OP_VAL==user_id)
  {
     parent_window.document.getElementById("AutoUserOp").value="";
     parent_window.document.getElementById("AutoUserOpName").value="";
     unset_op();
  }
  else
  {
    parent_window.document.getElementById("AutoUserOp").value=user_id;
    parent_window.document.getElementById("AutoUserOpName").value=user_name;
    
    set_op(user_id,user_name);
    
    if(!(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0))
      click_user(user_id);
  }
  begin_set();
}

function borderize_on(targetelement)
{
 color="#003FBF";
 targetelement.style.borderColor="black";
 targetelement.style.backgroundColor=color;
 targetelement.style.color="white";
 targetelement.style.fontWeight="bold";
}

function borderize_off(targetelement)
{
  targetelement.style.backgroundColor="";
  targetelement.style.borderColor="";
  targetelement.style.color="";
  targetelement.style.fontWeight="";
}

function begin_set()
{
  TO_VAL=parent_window.document.getElementById("AutoUser").value;
  OP_VAL=parent_window.document.getElementById("AutoUserOp").value; 
  for (step_i=0; step_i<userlist.length; step_i++)
  {
	 user_id=userlist[step_i];
     if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
		borderize_on(document.getElementById(user_id));
	 else
		borderize_off(document.getElementById(user_id));
	
	 if(OP_VAL==user_id)
	 {
          borderize_on(document.getElementById(user_id+"_op"));
          document.getElementById("opbox_"+user_id).checked=true;
     }
     else
       	  borderize_off(document.getElementById(user_id+"_op"));
  }
}

function add_all()
{
  TO_VAL=parent_window.document.getElementById("AutoUser").value;
  for(step_i=0; step_i<userlist.length; step_i++)
  {
    user_id=userlist[step_i];
    user_name=document.getElementById(user_id).getAttribute("name");

    if(TO_VAL.indexOf(","+user_id+",")<0 && TO_VAL.indexOf(user_id+",")!=0)
    {
        parent_window.document.getElementById("AutoUser").value+=user_id+",";
        parent_window.document.getElementById("AutoUserName").value+=user_name+",";
        
        borderize_on(document.getElementById(user_id));
    }
  }
}

function del_all()
{
  OP_VAL=parent_window.document.getElementById("AutoUserOp").value;
  for(step_i=0; step_i<userlist.length; step_i++)
  {
    TO_VAL=parent_window.document.getElementById("AutoUser").value;
    TO_NAME=parent_window.document.getElementById("AutoUserName").value;
    
    user_id=userlist[step_i];
    user_name=document.getElementById(user_id).getAttribute("name");
    
    if(user_id==OP_VAL)
    {
        parent_window.document.getElementById("AutoUserOp").value="";
        parent_window.document.getElementById("AutoUserOpName").value="";
    }
	if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
	{
		if(TO_VAL.indexOf(user_id+",")==0)    
			parent_window.document.getElementById("AutoUser").value=parent_window.document.getElementById("AutoUser").value.replace(user_id+",","");
	   
		if(TO_VAL.indexOf(","+user_id+",")>0)   
			parent_window.document.getElementById("AutoUser").value=parent_window.document.getElementById("AutoUser").value.replace(","+user_id+",",",");
		  
		if(TO_NAME.indexOf(user_name+",")==0)
			parent_window.document.getElementById("AutoUserName").value=parent_window.document.getElementById("AutoUserName").value.replace(user_name+",","");
	     
		if(TO_NAME.indexOf(","+user_name+",")>0)
			parent_window.document.getElementById("AutoUserName").value=parent_window.document.getElementById("AutoUserName").value.replace(","+user_name+",",",");
	}
  }
  begin_set();
}
		</script>
	</HEAD>
	<body class="bodycolor" topmargin="1" leftmargin="0" onload="begin_set()">
		<form id="Form1" method="post" runat="server">
			<table border="1" cellspacing="0" width="100%" class="small" cellpadding="3" bordercolorlight="#000000"
				bordercolordark="#ffffff">				
				<tr class="TableHeader">
					<td colspan="2" align="center"><b><asp:Literal id="litTitle" runat="server"></asp:Literal></b></td>
				</tr>
				<asp:Panel id="pnlMain" runat="server">
				<tr class="TableContent">
					<td onclick="javascript:add_all();" style="cursor: pointer; cursor: hand;" align="center" colspan="2">全部添加</td>
				</tr>
				<tr class="TableContent">
					<td onclick="javascript:del_all();" style="cursor: pointer; cursor: hand;" align="center" colspan="2">全部删除</td>
				</tr>
				</asp:Panel>
				<asp:Repeater id="rptUser" runat="server">
					<ItemTemplate>
						<tr class="TableControl">
							<td title="设为主办人" id="<%#Eval("UserId")%>_op" name="<%#Eval("UserName")%>" width="50" align="center"
								onclick="javascript:click_op('<%#Eval("UserId")%>_op')" style="cursor: pointer; cursor: hand;">
								<input type="checkbox" id="opbox_<%#Eval("UserId")%>">主办
							</td>
							<td title="<%#Eval("DeptName")%>" id="<%#Eval("UserId")%>" name="<%#Eval("UserName")%>" align="center" onclick="javascript:click_user('<%#Eval("UserId")%>')"
								style="cursor: pointer; cursor: hand;">
								<%#Eval("UserName")%>
							</td>
						</tr>
					</ItemTemplate>
				</asp:Repeater>
				<asp:Literal id="litMessage" Runat="server"></asp:Literal>
			</table>
		</form>
	</body>
</HTML>
